package online.flowerinsnow.minecraft.bukkit.manhunt.listener;

import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import online.flowerinsnow.minecraft.bukkit.manhunt.Manhunt;

import java.util.HashSet;
import java.util.UUID;

public class InvisibleListener implements Listener {
    public static final HashSet<UUID> INVISIBLE_PLAYERS = new HashSet<>();
    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        Bukkit.getOnlinePlayers().forEach(p -> {
            if (INVISIBLE_PLAYERS.contains(p.getUniqueId())) {
                e.getPlayer().hidePlayer(Manhunt.getInstance(), p);
            }
        });
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent e) {
        INVISIBLE_PLAYERS.remove(e.getPlayer().getUniqueId());
    }
}
